<?php
namespace Crm\Table;

class FavoritesTable extends AbstractTable
{
	protected $table = 'hy_favorites';
	protected $id = 'favorite_id';
	
	public function updateItem($id,$data){
		if(empty($id)){
			throw new \Exception("id field is invalid!");
		}
		$data = array(
			'user_id'=>$data['user_id'],
			'org_id'=>$data['org_id']
		);
		return $this->update($data,array('favorite_id'=>$id));
	}
	
	public function deleteItem($id){
		if(empty($id)){
			throw new Exception("id field is invalid!");
		}
		return $this->delete(array('favorite_id'=>$id));
		
	}
	
	public function addItem($data){
		
		$data = array(
			'user_id'=>$data['user_id'],
			'org_id'=>$data['org_id']
		);
		

		$this->insert($data);
		$id = $this->lastInsertValue;

		return $id;
	}
	
	public function getItem($id){
		if(empty($id)){
			throw new Exception("id field is invalid!");
		}
		$sql='SELECT * FROM `hy_favorites` WHERE `favorite_id` =:favorite_id';
		$statement=$this->getAdapter()->query($sql);
		$results=$statement->execute(array(':favorite_id'=>$id));
		$row=$results->current();
		return $row;
	}
}